# Built-In Example AI

# Title: HOPE Turtle
# Author: Evan Ju
# Version: 1.0.0
# Date: 5/6/2021

import math
import random
import game.tcturtle

class CombatTurtle(game.tcturtle.TurtleParent):
    """

        ai introduce of HOPE team
    """

    # -------------------------------------------------------------------------

    def class_name():
        """CombatTurtle.class_name() -> str
        Static method to return the name of the Combat Turtle AI.
        """

        return "要相信光"

    # -------------------------------------------------------------------------

    def class_desc():
        """CombatTurtle.class_desc() -> str
        Static method to return a description of the Combat Turtle AI.
        """

        return "HOPE——一群靓仔靓妹"

    # -------------------------------------------------------------------------

    def class_shape():
        """CombatTurtle.class_shape() -> (int or tuple)
        Static method to define the Combat Turtle's shape image.

        The return value can be either an integer or a tuple of tuples.

        Returning an integer index selects one of the following preset shapes:
            0 -- arrowhead (also default in case of unrecognized index)
            1 -- turtle
            2 -- plow
            3 -- triangle
            4 -- kite
            5 -- pentagon
            6 -- hexagon
            7 -- star

        A custom shape can be defined by returning a tuple of the form
        (radius, angle), where radius is a tuple of radii and angle is a tuple
        of angles (in radians) describing the polar coordinates of a polygon's
        vertices. The shape coordinates should be given for a turtle facing
        east.
        """

        return ((16.9,17.6,17.7,18.1,18.0,13.1,17.4,16.3,15.2,13.9,12.4,
                 10.9,10.0,8.6,9.1,9.5,9.6,10.0,9.7,12.9,16.7,13.5,16.7,12.9,
                 9.9,10.0,10.0,9.9,9.5,9.0,8.7,10.0,11.0,12.0,13.0,13.7,14.4,
                 15.0,15.3,15.9,16.1,16.0,16.2,11.1,14.3,12.8,13.2,12.0,11.3,
                 10.7,10.4,12.7,13.8,14.6,15.1,15.0,14.4,13.4,12.4,11.2,10.1,
                 10.0,10.1,11.2,12.4,13.4,14.2,14.7,14.7,13.8,12.5,11.1,10.0,
                 8.3,7.3,8.6,9.8,11.8,13.6,14.5,15.6,16.1),
                (0,math.pi/72,math.pi/51.43,math.pi/30.17,
                 math.pi/28.94,math.pi/13.23,math.pi/7.03,
                 math.pi/6.08,math.pi/5.59,math.pi/5.30,
                 math.pi/5.08,math.pi/5.30,math.pi/5.37,
                 math.pi/1.40,math.pi/4.87,math.pi/4.05,
                 math.pi/4.05,math.pi/3.68,math.pi/3.15,
                 math.pi/3.57,math.pi/2.45,math.pi/2.02,
                 math.pi/1.71,math.pi/1.40,math.pi/1.44,
                 math.pi/1.39,math.pi/1.35,math.pi/1.31,
                 math.pi/1.26,math.pi/1.23,math.pi/1.20,
                 math.pi/1.16,math.pi/1.12,math.pi/1.10,
                 math.pi/1.08,math.pi/1.05,math.pi/1.03,
                 math.pi/1.01,math.pi/1,math.pi/0.96,
                 math.pi/0.94,math.pi/0.93,math.pi/0.93,
                 math.pi/0.84,math.pi/0.73,math.pi/0.83,
                 math.pi/0.83,math.pi/0.82,math.pi/0.83,
                 math.pi/0.82,math.pi/0.82,math.pi/0.79,
                 math.pi/0.79,math.pi/0.76,math.pi/0.75,
                 math.pi/0.74,math.pi/0.72,math.pi/0.71,
                 math.pi/0.70,math.pi/0.69,math.pi/0.68,
                 math.pi/0.68,math.pi/0.68,math.pi/0.64,
                 math.pi/0.64,math.pi/0.62,math.pi/0.61,
                 math.pi/0.60,math.pi/0.60,math.pi/0.59,
                 math.pi/0.57,math.pi/0.57,math.pi/0.55,
                 math.pi/0.53,math.pi/0.53,math.pi/0.53,
                 math.pi/0.51,math.pi/0.51,math.pi/0.51,
                 math.pi/0.50,math.pi/0.50,math.pi/0.50)
                )

    # =========================================================================

    def setup(self):
        """CombatTurtle.setup() -> None
        Initialization code for Combat Turtle.
        """

        # Define parameters for variations
        self.wander_amp = 99 # amplitude of sinusoidal wandering noise (deg)
        self.wander_wl = 99  # wavelength of sinusoidal wandering noise (steps)
        self.approach_amp = 1.5 * self.missile_radius  # amplitude of sinusoidal
        # approach radius
        self.approach_wl = 99  # wavelength of sinusoidal approach radius
        self.shoot_prob = 99  # probability to shoot when the option exists

    # -------------------------------------------------------------------------

    def step(self):
        """CombatTurtle.setup() -> None
        Step event code for Combat Turtle.
        """

        count = 0

        # Get direction towards opponent and add sinusoidal noise
        dir = self.heading_towards()
        dir += self.wander_amp * math.sin((2 * math.pi * self.time) / self.wander_wl)

        # Turn towards the specified heading
        self.turn_towards(dir)

        # Determine minimum approach distance by adding noise
        dist = 4 * self.missile_radius
        dist += self.approach_amp * math.sin((2 * math.pi * self.time)
                                             / self.approach_wl)

        # Move towards opponent (or away if too close)
        if self.distance() > dist:
            self.forward()
        else:
            self.backward()

            # Shoot if facing opponent and there is line of sight
        if (self.can_shoot and abs(self.relative_heading_towards()) <= 10 and
                self.line_of_sight()):
            self.shoot()
